﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using ProjectCore.Application;
using ProjectCore.Common;
using ProjectCore.Domain.Model.Entity;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace ProjectCore.WebApi.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class ProductTypeController : ControllerBase
    {
        private readonly IAppProductType appProductType;
        public ProductTypeController(IAppProductType _appAdmin)
        {
            appProductType = _appAdmin;
        }
        /// <summary>
        /// 获取商品分类集合
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<ActionResult> GetProductTypes(int pageIndex, int pageSize)
        {
            Task<HeaderResult<List<ProductType>>> productTypes = appProductType.GetProductTypes(pageIndex,pageSize);
            return Ok(new { data = await productTypes });
        }


        /// <summary>
        /// 逻辑删除
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ActionResult> IsDel(int Id)
        {
            Task<int> n = appProductType.IsDel(Id);
            return Ok(new
            {
                data = await n
            });
        }


        /// <summary>
        /// 获取商品分类数据
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ActionResult> GetProductType(int Id)
        {
            Task<ProductType> productType = appProductType.GetProductType(Id);
            return Ok(new
            {
                data = await productType
            });
        }


        /// <summary>
        /// 商品分类修改
        /// </summary>
        /// <param name="productType"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ActionResult> UptProductType(ProductType productType)
        {
            Task<int> n = appProductType.UptProductType(productType);
            return Ok(new
            {
                data = await n
            });
        }
    }
}
